home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / human interface toolbox / packagetool / packageutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  4.5 KB  |  100 lines

  1. /*
  2.     File: PackageUtils.c
  3.     
  4.     Description:
  5.         PackageTool is an application illustrating how to create application
  6.     packages in Mac OS 9.  It provides a simple interface for converting
  7.     correctly formatted folders into packages and vice versa.
  8.  
  9.     Copyright:
  10.         © Copyright 1999 Apple Computer, Inc. All rights reserved.
  11.     
  12.     Disclaimer:
  13.         IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  14.         ("Apple") in consideration of your agreement to the following terms, and your
  15.         use, installation, modification or redistribution of this Apple software
  16.         constitutes acceptance of these terms.  If you do not agree with these terms,
  17.         please do not use, install, modify or redistribute this Apple software.
  18.  
  19.         In consideration of your agreement to abide by the following terms, and subject
  20.         to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  21.         copyrights in this original Apple software (the "Apple Software"), to use,
  22.         reproduce, modify and redistribute the Apple Software, with or without
  23.         modifications, in source and/or binary forms; provided that if you redistribute
  24.         the Apple Software in its entirety and without modifications, you must retain
  25.         this notice and the following text and disclaimers in all such redistributions of
  26.         the Apple Software.  Neither the name, trademarks, service marks or logos of
  27.         Apple Computer, Inc. may be used to endorse or promote products derived from the
  28.         Apple Software without specific prior written permission from Apple.  Except as
  29.         expressly stated in this notice, no other rights or licenses, express or implied,
  30.         are granted by Apple herein, including but not limited to any patent rights that
  31.         may be infringed by your derivative works or by other works in which the Apple
  32.         Software may be incorporated.
  33.  
  34.         The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  35.         WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  36.         WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  37.         PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  38.         COMBINATION WITH YOUR PRODUCTS.
  39.  
  40.         IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  41.         CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  42.         GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43.         ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  44.         OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  45.         (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  46.         ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  
  48.     Change History (most recent first):
  49.         Fri, Dec 17, 1999 -- created
  50. */
  51.  
  52.  
  53.  
  54. #include "PackageUtils.h"
  55. #include <Aliases.h>
  56.  
  57. /* IdentifyPackage returns true if the file system object refered to
  58.     by *target refers to a package.  If it is a package, then 
  59.     *mainPackageFile is set to refer to the package's main file. */
  60. Boolean IdentifyPackage(FSSpec *target, FSSpec *mainPackageFile) {
  61.     CInfoPBRec cat;
  62.     OSErr err;
  63.     long packageFolderDirID;
  64.     Str255 name;
  65.     FSSpec aliasFile;
  66.     Boolean targetIsFolder, wasAliased;
  67.         /* check the target's flags */
  68.     cat.dirInfo.ioNamePtr = target->name;
  69.     cat.dirInfo.ioVRefNum = target->vRefNum;
  70.     cat.dirInfo.ioFDirIndex = 0;
  71.     cat.dirInfo.ioDrDirID = target->parID;
  72.     err = PBGetCatInfoSync(&cat);
  73.     if (err != noErr) return false;
  74.     if (((cat.dirInfo.ioFlAttrib & 16) != 0) && ((cat.dirInfo.ioDrUsrWds.frFlags & kHasBundle) != 0)) {
  75.             /* search for a top level alias file */
  76.         packageFolderDirID = cat.dirInfo.ioDrDirID;
  77.         cat.dirInfo.ioNamePtr = name;
  78.         cat.dirInfo.ioVRefNum = target->vRefNum;
  79.         cat.dirInfo.ioFDirIndex = 1;
  80.         cat.dirInfo.ioDrDirID = packageFolderDirID;
  81.             /* find the first alias file in the directory */
  82.         while (PBGetCatInfoSync(&cat) == noErr) {
  83.             if (((cat.dirInfo.ioFlAttrib & 16) == 0) && ((cat.dirInfo.ioDrUsrWds.frFlags & kIsAlias) != 0)) {
  84.                 err = FSMakeFSSpec(target->vRefNum, packageFolderDirID, name, &aliasFile);
  85.                 if (err != noErr) return false;
  86.                 err = ResolveAliasFile(&aliasFile, false, &targetIsFolder, &wasAliased);
  87.                 if (err != noErr) return false;
  88.                 if (mainPackageFile != NULL)
  89.                     *mainPackageFile = aliasFile;
  90.                 return true;
  91.             }
  92.             cat.dirInfo.ioFDirIndex++;
  93.             cat.dirInfo.ioDrDirID = packageFolderDirID;
  94.         }
  95.     }
  96.         /* no matching files found */
  97.     return false;
  98. }
  99.  
  100.